//
// Created by Jisam on 2024/5/28.
// 11点47分
#include "bits/stdc++.h"

using namespace std;
#define  int long long
const int MAXN = 105;
int a[MAXN][MAXN], vis[MAXN][MAXN];
struct node {
    int x, y;
};
int dx[4] = {1, -1, 0, 0,};
int dy[4] = {0, 0, 1, -1,};
int n, m;
int idx = 2;

void bfs(node x) {
    queue<node> q;
    q.push(x);
    while (q.size()) {
        node t = q.front();
        q.pop();
        vis[t.x][t.y] = 1;

        if ((t.x > n && t.y > m ) || a[t.x][t.y] == 0) {
            return;
        }
        a[t.x][t.y] = idx;
        for (int i = 0; i < 4; i++) {
            int tx = t.x + dx[i];
            int ty = t.y + dy[i];
            if (tx > 0 && ty > 0 && tx <= n && ty <= m && !vis[tx][ty] && a[tx][ty] ) {
                q.push((node) {tx, ty});
                vis[tx][ty] = 1;
            }
        }
    }
    idx ++;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            cout << a[i][j];
        cout << endl;
    }
}

signed main() {
    memset(vis,0,sizeof vis);
    cin >> n >> m;
    char x;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> x;
            if (x != '0') a[i][j] = 1;
            else a[i][j] = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            cout << a[i][j];
        cout << endl;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            if (!vis[i][j]) {
                bfs({node{i, j}});}
    }
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= m; j++)
//            cout << a[i][j];
//        cout << endl;
//    }

    cout << idx -2;
    return 0;
}
